[BLOCK] blkback: Fix potential grant entry leaks on error
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 25 Oct 2006 09:59:00 +0000 (10:59 +0100)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 25 Oct 2006 09:59:00 +0000 (10:59 +0100)
As it stands grant entries for the actual data are mapped in bulk.
If one of the earlier entries fail to be mapped, it can cause all
subsequent entries to be leaked if they were successfully mapped.

This patch changes it so that we will continue to reap grant entries
even when an error is detected.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c

index 37b33cbe4dfeaac08ec772c9c4d883e242619023..e9a7e7d0703a0bf3c363c2ad8c3b341d8ce49320 100644 (file)
@@ -392,10 +392,15 @@ static void dispatch_rw_block_io(blkif_t *blkif,
        for (i = 0; i < nseg; i++) {
                if (unlikely(map[i].status != 0)) {
                        DPRINTK("invalid buffer -- could not remap it\n");
-                       goto fail_flush;
+                       map[i].handle = BLKBACK_INVALID_HANDLE;
+                       ret |= 1;
                }
 
                pending_handle(pending_req, i) = map[i].handle;
+
+               if (ret)
+                       continue;
+
                set_phys_to_machine(__pa(vaddr(
                        pending_req, i)) >> PAGE_SHIFT,
                        FOREIGN_FRAME(map[i].dev_bus_addr >> PAGE_SHIFT));
@@ -403,6 +408,9 @@ static void dispatch_rw_block_io(blkif_t *blkif,
                        (req->seg[i].first_sect << 9);
        }
 
+       if (ret)
+               goto fail_flush;
+
        if (vbd_translate(&preq, blkif, operation) != 0) {
                DPRINTK("access denied: %s of [%llu,%llu] on dev=%04x\n", 
                        operation == READ ? "read" : "write",